<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Midjourney Proxy Demo</title>
    <script src="//cdn.socket.io/4.7.2/socket.io.min.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        min-height: 100vh;
        padding: 20px;
      }

      .container {
        max-width: 1200px;
        margin: 0 auto;
        background: white;
        border-radius: 15px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        overflow: hidden;
      }

      .header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 30px;
        text-align: center;
      }

      .header h1 {
        font-size: 2.5em;
        margin-bottom: 10px;
      }

      .header p {
        font-size: 1.2em;
        opacity: 0.9;
      }

      .content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        padding: 30px;
      }

      .section {
        background: #f8f9fa;
        border-radius: 10px;
        padding: 25px;
        border: 1px solid #e9ecef;
      }

      .section h3 {
        color: #495057;
        margin-bottom: 20px;
        font-size: 1.4em;
        border-bottom: 2px solid #667eea;
        padding-bottom: 10px;
      }

      .form-group {
        margin-bottom: 20px;
      }

      .form-group label {
        display: block;
        margin-bottom: 8px;
        color: #495057;
        font-weight: 600;
      }

      .form-group input,
      .form-group select,
      .form-group textarea {
        width: 100%;
        padding: 12px;
        border: 2px solid #e9ecef;
        border-radius: 8px;
        font-size: 14px;
        transition: border-color 0.3s ease;
      }

      .form-group input:focus,
      .form-group select:focus,
      .form-group textarea:focus {
        outline: none;
        border-color: #667eea;
      }

      .btn {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        padding: 12px 25px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
        transition: transform 0.2s ease;
      }

      .btn:hover {
        transform: translateY(-2px);
      }

      .btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none;
      }

      .status {
        padding: 15px;
        border-radius: 8px;
        margin-bottom: 20px;
        font-weight: 600;
      }

      .status.connected {
        background: #d4edda;
        color: #155724;
        border: 1px solid #c3e6cb;
      }

      .status.disconnected {
        background: #f8d7da;
        color: #721c24;
        border: 1px solid #f5c6cb;
      }

      .messages {
        background: white;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        height: 300px;
        overflow-y: auto;
        padding: 15px;
        margin-bottom: 20px;
      }

      .message {
        background: #f8f9fa;
        padding: 10px;
        margin-bottom: 10px;
        border-radius: 8px;
        border-left: 4px solid #667eea;
      }

      .message .time {
        font-size: 12px;
        color: #6c757d;
        margin-bottom: 5px;
      }

      .message .content {
        color: #495057;
      }

      .message .sender {
        font-weight: 600;
        color: #667eea;
      }

      .rooms {
        display: flex;
        gap: 10px;
        margin-bottom: 20px;
        flex-wrap: wrap;
      }

      .room-btn {
        background: #e9ecef;
        border: none;
        padding: 8px 15px;
        border-radius: 20px;
        cursor: pointer;
        font-size: 12px;
        transition: all 0.3s ease;
      }

      .room-btn.active {
        background: #667eea;
        color: white;
      }

      .room-btn:hover {
        background: #667eea;
        color: white;
      }

      .stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        margin-bottom: 20px;
      }

      .stat-card {
        background: white;
        padding: 15px;
        border-radius: 8px;
        text-align: center;
        border: 1px solid #e9ecef;
      }

      .stat-number {
        font-size: 2em;
        font-weight: bold;
        color: #667eea;
      }

      .stat-label {
        color: #6c757d;
        font-size: 14px;
      }

      @media (max-width: 768px) {
        .content {
          grid-template-columns: 1fr;
          gap: 20px;
          padding: 20px;
        }

        .header h1 {
          font-size: 2em;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="header">
        <h1>🚀 Midjourney Proxy Demo</h1>
        <p>实时聊天和WebSocket功能演示</p>
      </div>

      <div class="content">
        <!-- 连接状态和认证 -->
        <div class="section">
          <h3>🔌 连接状态</h3>
          <div id="connectionStatus" class="status disconnected">未连接</div>

          <div class="form-group">
            <label for="token">JWT Token (可选):</label>
            <input type="text" id="token" placeholder="输入JWT token进行认证" />
          </div>

          <button class="btn" id="connectBtn">连接</button>
          <button class="btn" id="disconnectBtn" style="margin-left: 10px">
            断开
          </button>
          <button
            class="btn"
            id="testCorsBtn"
            style="margin-left: 10px; background: #28a745"
          >
            测试跨域
          </button>

          <div class="stats">
            <div class="stat-card">
              <div class="stat-number" id="userCount">0</div>
              <div class="stat-label">在线用户</div>
            </div>
            <div class="stat-card">
              <div class="stat-number" id="roomCount">0</div>
              <div class="stat-label">活跃房间</div>
            </div>
          </div>
        </div>

        <!-- 聊天功能 -->
        <div class="section">
          <h3>💬 聊天功能</h3>

          <div class="form-group">
            <label for="roomSelect">选择房间:</label>
            <select id="roomSelect">
              <option value="general">通用聊天室</option>
              <option value="tech">技术讨论</option>
              <option value="random">随机话题</option>
            </select>
          </div>

          <div class="form-group">
            <label for="messageInput">消息内容:</label>
            <textarea
              id="messageInput"
              rows="3"
              placeholder="输入要发送的消息..."
            ></textarea>
          </div>

          <button class="btn" id="sendMessageBtn">发送消息</button>
          <button class="btn" id="joinRoomBtn" style="margin-left: 10px">
            加入房间
          </button>
        </div>

        <!-- 消息显示 -->
        <div class="section" style="grid-column: 1 / -1">
          <h3>📨 消息记录</h3>
          <div id="messages" class="messages">
            <div class="message">
              <div class="time">系统</div>
              <div class="content">
                欢迎使用 Midjourney Proxy Demo！请先连接WebSocket服务。
              </div>
            </div>
          </div>

          <div class="rooms">
            <button class="room-btn active" data-room="general">
              通用聊天室
            </button>
            <button class="room-btn" data-room="tech">技术讨论</button>
            <button class="room-btn" data-room="random">随机话题</button>
          </div>
        </div>
      </div>
    </div>

    <script src="/app.js"></script>
  </body>
</html>
